package com.wlan.dao.manage;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.hibernate.criterion.Restrictions;

import com.wlan.dao.common.AbstractTestCase;
import com.wlanauth.core.criteria.GeneralCriteria;
import com.wlanauth.core.criteria.GeneralCriteriaResult;
import com.wlanauth.core.exception.ServiceException;
import com.wlanauth.core.util.MD5Util;
import com.wlanauth.domain.manage.Operator;

public class OperatorTestCase extends AbstractTestCase {

	public void testQuery(){
		
		Date d = new Date();
		d.setTime(1342064329090L);
		String s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(d);
		System.out.println(s);
		GeneralCriteria criteria = new GeneralCriteria(Operator.class);
		criteria.createAlias("role", "r",GeneralCriteria.LEFT_JOIN);
//		criteria.createAlias("roles.privileges", "p",GeneralCriteria.FULL_JOIN);
//		criteria.createAlias("roles.privileges.resources", "rs",GeneralCriteria.FULL_JOIN);
//		criteria.createAlias("roles.privileges.actions", "a",GeneralCriteria.FULL_JOIN);
		
		criteria.add(Restrictions.eq("username", "zz"));
		
		GeneralCriteriaResult<Operator> result = criteria.executeQuery();
		
		
		//if(result.getData() == null||result.getData().size()<1)
		if(result.getData().size()>1) throw new ServiceException("期待返回1个结果,实际返回"+result.getData().size()+"个结果");
	
		for(Operator a:result.getData()){
			System.out.println("操作员："+a.getId());
			
		}
		
		
	}
	
}
